package com.sq.util.encrypt;

import com.sq.util.ByteUtil;
import com.sq.util.encrypt.ecdsa.ECDSASignature;
import com.sq.util.encrypt.ecdsa.ECKey;

/**
 * @author sq
 *
 */
public class Ecdsa extends ECDSASignature {

    public static Key genKey() {
        ECKey k = new ECKey();
        Key key = new Key();
        key.setHexPrivateKey(ByteUtil.toHexString(k.getPrivateKey()));
        key.setHexPublicKey(ByteUtil.toHexString(k.getPublicKey()));
        return key;
    }

    /**
     * 产生签名
     */
    public static byte[] sign(byte[] data, String hexPrivateKey) {
        return ECDSASignature.sign(data, hexPrivateKey);
    }

    /**
     * 验证签名
     */
    public static boolean verifySign(byte[] data, byte[] sign, String hexPublicKey) {
        return ECDSASignature.verify(data, sign, ByteUtil.toBytes(hexPublicKey));
    }
}
